Repository navigation
Query every field of every test schema - #879
Merged
Merged
Conversation
|
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Checklist
Description
A schema that builds can still fail as soon as a field is queried. In #203 a resolver declared as
Future<Organization>returned RxJava'sSingle#toFuture(). The build was fine since the scanner unwrapsFuture, but graphql-java only waits on aCompletionStage, so the child fields failed withExpected source object to be an instance of '...Organization'. Our tests only run the fields someone wrote a query for, so nothing caught it.assertEveryFieldResolves()(new, inEveryFieldResolves.kt) is an extension onGraphQLSchemathat returns the schema, so it goes at the end of the builder chain, right aftermakeExecutableSchema(). It runs one operation per root field that selects every field reachable from it, and fails on any GraphQL error:"a","1"forID,1,1.5,true, the first enum value, input objects filled the same way, one field for@oneOf)excepttakes schema coordinates (Type.fieldorType.field(arg:)) for fields that fail on purpose, or arguments whose made-up value doesn't fit, like a UUIDIDor a relay cursorExecutionInput, e.g. a context or a data loader registryIt's called after 163 schema builds in 36 test files. Schemas built once per class get a single
every field resolvestest instead (8 of them), and builds insidewithWarnings { }call it after the block, so its queries can't add to the warnings. The builds left without a check either throw, or fail on every field on purpose (allowUnimplementedResolversin the description tests, the Spring AOP proxy test, the misspelled input class tests, the rethrow test, futures graphql-java can't wait on).Fixtures that couldn't be queried are fixed without changing what their tests assert: resolvers returning null for non-null fields, private or inner classes Jackson can't construct, input classes missing a schema field, non-null Kotlin parameters for nullable arguments. Two worth a look:
DeprecatedDirectiveTestusedusers(env: DataFetchingEnvironment)for bothusers(first: Int)andusers(connectionInput: ConnectionInput). The argument got mapped ontoenv, sousersfailed on every query. It now has one resolver per argument shape.SchemaParserTestused the plainGenericWrapper(CustomGenericWrapper::class, 1)constructor, and its resolvers returned null. With a real value, the wrapper reached graphql-java as is (Expected source object to be an instance of '...Obj' but instead got '...CustomGenericWrapper'), since that constructor passes the value through. It useswithTransformernow. The scanner only reads the type and index, so the scanning part is the same.The Kotlin
test-compileexecution moves toprocess-test-sources(like the main one atprocess-sources), so the Kotlin test classes exist before javac compiles the Java tests.ResolverMethodsTest.javaneeds that to call the helper.It found two library bugs I didn't fix here:
InputResolver<I>.generic(input: I)withGreetingQuery : InputResolver<GreetingInput>()), builds but fails on every query withTypeVariableImpl cannot be cast to class java.lang.Class. The data fetcher uses the unresolvedIfromMethod#getGenericParameterTypes. Reproduced through the public API on graphql-java 26.1 and 25.1. Filed as Resolver parameter typed by the resolver's own type variable fails on every query #880, andQuery.genericis excluded inUnmappedInputFieldsTestuntil it's fixed.DataFetchingEnvironmentbuilds without a warning, with the argument mapped onto that parameter. The field then fails on every query (theDeprecatedDirectiveTestcase above). Same family as Last argument to field resolver is not checked when using the context class schema parser option #418, so I added it there.Limits: it only runs what the test resolvers return, so a union member a resolver never returns, or the fields under a null, aren't run. Fields with a required custom scalar argument are skipped, since there's no value to make up.
Test only, no library changes.
mvn clean verifypasses on JDK 25 and JDK 11, and against graphql-java 25.1.